﻿using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;

namespace ToyundaPhone.Helpers
{
	public class HighlightStyle : DependencyObject
	{
		public static readonly DependencyProperty FontFamilyProperty =
			DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(HighlightStyle), new PropertyMetadata(null));
		public static readonly DependencyProperty FontSizeProperty =
			DependencyProperty.Register("FontSize", typeof(double?), typeof(HighlightStyle), new PropertyMetadata(null));
		public static readonly DependencyProperty FontStretchProperty =
			DependencyProperty.Register("FontStretch", typeof(FontStretch?), typeof(HighlightStyle), new PropertyMetadata(null));
		public static readonly DependencyProperty FontStyleProperty =
			DependencyProperty.Register("FontStyle", typeof(FontStyle?), typeof(HighlightStyle), new PropertyMetadata(null));
		public static readonly DependencyProperty FontWeightProperty =
			DependencyProperty.Register("FontWeight", typeof(FontWeight?), typeof(HighlightStyle), new PropertyMetadata(null));
		public static readonly DependencyProperty ForegroundProperty =
			DependencyProperty.Register("Foreground", typeof(Brush), typeof(HighlightStyle), new PropertyMetadata(null));

		public FontFamily FontFamily
		{
			get { return GetValue(FontFamilyProperty) as FontFamily; }
			set { SetValue(FontFamilyProperty, value); }
		}
		public double? FontSize
		{
			get { return (double?)GetValue(FontSizeProperty); }
			set { SetValue(FontSizeProperty, value); }
		}
		public FontStretch? FontStretch
		{
			get { return (FontStretch?)GetValue(FontStretchProperty); }
			set { SetValue(FontStretchProperty, value); }
		}
		public FontStyle? FontStyle
		{
			get { return (FontStyle?)GetValue(FontStyleProperty); }
			set { SetValue(FontStyleProperty, value); }
		}
		public FontWeight? FontWeight
		{
			get { return (FontWeight?)GetValue(FontWeightProperty); }
			set { SetValue(FontWeightProperty, value); }
		}
		public Brush Foreground
		{
			get { return GetValue(ForegroundProperty) as Brush; }
			set { SetValue(ForegroundProperty, value); }
		}

		public void Apply(TextElement element)
		{
			if (FontFamily != null) element.FontFamily = FontFamily;
			if (FontSize.HasValue) element.FontSize = FontSize.Value;
			if (FontStretch.HasValue) element.FontStretch = FontStretch.Value;
			if (FontStyle.HasValue) element.FontStyle = FontStyle.Value;
			if (FontWeight.HasValue) element.FontWeight = FontWeight.Value;
			if (Foreground != null) element.Foreground = Foreground;
		}
	}
}
